package com.wangxiang.sys.manage.utils;

import com.wangxiang.sys.manage.dao.InfoDao;
import com.wangxiang.sys.manage.dao.LoginDao;
import com.wangxiang.sys.manage.dao.LoginLogDao;
import com.wangxiang.sys.manage.entity.InfoEntity;
import com.wangxiang.sys.manage.entity.LoginEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;


@Component
public class getInfo {
    @Autowired
    private LoginLogDao loginLogDao;
    @Autowired
    private LoginDao loginDao;

    public InfoEntity getInfoClass(int userId){
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        LoginEntity loginEntity = loginDao.getSysUserByUserId(userId);
        InfoEntity infoEntity = new InfoEntity();
        infoEntity.setUserId(loginEntity.getUserId());
        infoEntity.setUserName(loginEntity.getLoginId());
        infoEntity.setEmail(loginEntity.getEmail());
        infoEntity.setCall(loginEntity.getMobail());
        //获取时间
        List<Date> timeList = loginLogDao.getTimeByUserId(userId);
        Date date = timeList.get(timeList.size() - 1);
        String time = df.format(date);
        infoEntity.setTime(time);

        return infoEntity;
    }

}
